<template>
    <view class="tab-bar">
        <view v-for="(item,index) in list" :key="index" class="tab-bar-item" @click="switchTab(item, index)">
            <image class="tab_img" :src="currentIndex == index ? item.selectedIconPath : item.iconPath" ></image>
            <view class="tab_text" :style="{color: currentIndex == index ? selectedColor : color}">{{item.text}}</view>
        </view>
    </view>
</template>

<script>
	var path;
    export default {
        props: {
            selectedIndex: { // 当前选中的tab index
                default: 0
            },
        },
        data() {
            return {
                color: "#000000",
                selectedColor: "#000000",
                list: [],
                currentIndex:0,
            }
        },
        created() {
            this.currentIndex = this.selectedIndex;
            var _this = this
            if (uni.getStorageSync('identify') == '0') {
                _this.list = [{
                        "pagePath": "/pages/adminVue/orderView",
                        "iconPath": "/static/orderView.png",
                        "selectedIconPath": "/static/orderView.png",
                        "text": "工单审阅",
                    },
					{
					    "pagePath": "/pages/adminVue/my",
					    "iconPath": "/static/my.png",
					    "selectedIconPath": "/static/my.png",
					    "text": "我的",
					}
                ]
            } else if(uni.getStorageSync('identify') == '1'){
                _this.list = [{
                        "pagePath": "/pages/afterSaleVue/index/index",
                        "iconPath": "/static/工单.png",
                        "selectedIconPath": "/static/工单.png",
                        "text": "工单信息",
                    },
					{
					    "pagePath": "/pages/afterSaleVue/cate/cate",
					    "iconPath": "/static/打卡.png",
					    "selectedIconPath": "/static/打卡.png",
					    "text": "打卡签到",
					},
					{
					    "pagePath": "/pages/afterSaleVue/operationManual/personalCenter",
					    "iconPath": "/static/gerenzhongxin.png",
					    "selectedIconPath": "/static/gerenzhongxin.png",
					    "text": "个人中心",
					}
                ]
            }else{
				
				_this.list = [{
                        "pagePath": "/pages/clientVue/bindDevice",
                       "iconPath": "/static/bind.png",
                       "selectedIconPath": "/static/bind.png",
                        "text": "绑定设备",
                    },
					{
						"pagePath": "/pages/clientVue/applyAfterSale",
					   "iconPath": "/static/shouhou.png",
					   "selectedIconPath": "/static/shouhou.png",
						"text": "申请售后",
					},
					{
						"pagePath": "/pages/clientVue/my-client",
					   "iconPath": "/static/my.png",
					   "selectedIconPath": "/static/my.png",
						"text": "我的",
					},
					]
			}
        },
        methods: {
            switchTab(item, index) {
				
                this.currentIndex = index;
				// console.log("this.currentIndex   =======",this.currentIndex)
                let url = item.pagePath;
				path = url
				// console.log(url,"页面路径---------------")
                uni.switchTab({
					url:url,
					success() {
						let page = getCurrentPages().pop();  //跳转页面成功之后                                        
						if (!page) return;
						page.onLoad(); 						//如果页面存在，则重新刷新页面
					}
					})	
				
            },
		
        },
		
    }
</script>

<style lang="scss">
    .tab-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 100rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部

        .tab-bar-item {
            flex: 1;
            text-align: center;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            .tab_img {
                width: 37rpx;
                height: 41rpx;
            }
            .tab_text {
                font-size: 20rpx;
                margin-top: 9rpx;
            }
        }
    }
</style>
